
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>http · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="xml.html" />
    
    
    <link rel="prev" href="lang.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">----安卓 UI----</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="view.html">
            
                <a href="view.html">
            
                    
                    自定义控件和measure
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="canvas-paint.html">
            
                <a href="canvas-paint.html">
            
                    
                    draw和canvas，paint详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="anim.html">
            
                <a href="anim.html">
            
                    
                    动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="notify.html">
            
                <a href="notify.html">
            
                    
                    notify系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="loading.html">
            
                <a href="loading.html">
            
                    
                    loading系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="status-ui.html">
            
                <a href="status-ui.html">
            
                    
                    StatusUI系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="touch-scroll.html">
            
                <a href="touch-scroll.html">
            
                    
                    滑动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="layout.html">
            
                <a href="layout.html">
            
                    
                    Layout
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="textview.html">
            
                <a href="textview.html">
            
                    
                    TextView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="drawable.html">
            
                <a href="drawable.html">
            
                    
                    Drawable
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="item-template.html">
            
                <a href="item-template.html">
            
                    
                    列表Adapter模板化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="recyclerview.html">
            
                <a href="recyclerview.html">
            
                    
                    RecyclerView全解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="design.html">
            
                <a href="design.html">
            
                    
                    MeterialDesign详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="component.html">
            
                <a href="component.html">
            
                    
                    AyoComponent基础库--Activity和Fragment
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="systembartint.html">
            
                <a href="systembartint.html">
            
                    
                    SystembarTint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="permission-ask.html">
            
                <a href="permission-ask.html">
            
                    
                    权限控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="keyboard.html">
            
                <a href="keyboard.html">
            
                    
                    小键盘
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="notification.html">
            
                <a href="notification.html">
            
                    
                    Notification
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----安卓 foundation----</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="mvp.html">
            
                <a href="mvp.html">
            
                    
                    MVP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="rxjava.html">
            
                <a href="rxjava.html">
            
                    
                    RxJava
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="lang.html">
            
                <a href="lang.html">
            
                    
                    常用工具类
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.4" data-path="http.html">
            
                <a href="http.html">
            
                    
                    http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="xml.html">
            
                <a href="xml.html">
            
                    
                    xml解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="json-reporter.html">
            
                <a href="json-reporter.html">
            
                    
                    Json解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="inject.html">
            
                <a href="inject.html">
            
                    
                    ButterKnife
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="thread.html">
            
                <a href="thread.html">
            
                    
                    安卓线程和looper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="process.html">
            
                <a href="process.html">
            
                    
                    多进程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="eventbus.html">
            
                <a href="eventbus.html">
            
                    
                    EventBus
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="db.html">
            
                <a href="db.html">
            
                    
                    数据库和ContentProvider
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="job.html">
            
                <a href="job.html">
            
                    
                    定时任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="service.html">
            
                <a href="service.html">
            
                    
                    service
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="opt-mem.html">
            
                <a href="opt-mem.html">
            
                    
                    内存优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15" data-path="opt-network.html">
            
                <a href="opt-network.html">
            
                    
                    网络优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.16" data-path="opt-anr.html">
            
                <a href="opt-anr.html">
            
                    
                    anr排查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.17" data-path="opt-ui.html">
            
                <a href="opt-ui.html">
            
                    
                    UI卡顿优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.18" data-path="opt-launch.html">
            
                <a href="opt-launch.html">
            
                    
                    启动优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.19" data-path="opt-launch.html">
            
                <a href="opt-launch.html">
            
                    
                    混淆
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.20" data-path="hotfix.html">
            
                <a href="hotfix.html">
            
                    
                    热补丁混淆
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.21" data-path="aar.html">
            
                <a href="aar.html">
            
                    
                    aar相关
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.22" data-path="route.html">
            
                <a href="route.html">
            
                    
                    Route路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.23" data-path="modules.html">
            
                <a href="modules.html">
            
                    
                    分模块，组件化，插件化
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----Gradle----</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="gradle.html">
            
                <a href="gradle.html">
            
                    
                    gradle基本配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="gradle-plugin.html">
            
                <a href="gradle-plugin.html">
            
                    
                    gradle插件开发
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----工具----</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="repos.html">
            
                <a href="repos.html">
            
                    
                    优秀博客，开源项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="packs.html">
            
                <a href="packs.html">
            
                    
                    自动打包，多渠道打包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="gist.html">
            
                <a href="gist.html">
            
                    
                    代码片段和常见问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="stetho.html">
            
                <a href="stetho.html">
            
                    
                    stetho
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="fabric.html">
            
                <a href="fabric.html">
            
                    
                    fabric
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="app-update.html">
            
                <a href="app-update.html">
            
                    
                    自动升级
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="bugsnags.html">
            
                <a href="bugsnags.html">
            
                    
                    日志和崩溃统计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="mail.html">
            
                <a href="mail.html">
            
                    
                    发邮件辅助接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="socail.html">
            
                <a href="socail.html">
            
                    
                    第三方登录和分享
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="pay-alipay.html">
            
                <a href="pay-alipay.html">
            
                    
                    支付宝支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="pay-wx.html">
            
                <a href="pay-wx.html">
            
                    
                    微信支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.12" data-path="umeng.html">
            
                <a href="umeng.html">
            
                    
                    友盟统计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.13" data-path="push-jpush.html">
            
                <a href="push-jpush.html">
            
                    
                    推送-极光
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.14" data-path="push-xiaomi.html">
            
                <a href="push-xiaomi.html">
            
                    
                    推送-小米
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >http</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="http">http</h1>
<p>&#x6709;&#x7528;&#x7684;&#x5C31;3&#x4E2A;&#x6A21;&#x5757;&#xFF1A;ayohttp, converter-fastjson, worker-okhttp</p>
<p>&#x5176;&#x4ED6;&#x6A21;&#x5757;&#x662F;retrofit&#xFF0C;okhttp&#xFF0C;okhttpUtils&#x7684;demo&#x6D4B;&#x8BD5;</p>
<hr>
<h2 id="1-&#x57FA;&#x672C;&#x5957;&#x8DEF;">1 &#x57FA;&#x672C;&#x5957;&#x8DEF;</h2>
<ul>
<li>&#x53D1;&#x8D77;&#x4E00;&#x4E2A;&#x8BF7;&#x6C42;&#xFF0C;&#x5206;&#x4E3A;&#x51E0;&#x6B65;&#xFF1A;<ul>
<li>&#x914D;&#x7F6E;&#xFF1A;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x7B49;</li>
<li>&#x6784;&#x9020;&#x8BF7;&#x6C42;AyoHttp&#xFF1A;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#xFF0C;path&#x53C2;&#x6570;&#xFF0C;query&#x53C2;&#x6570;&#xFF0C;post&#x53C2;&#x6570;&#xFF0C;&#x4E0A;&#x4F20;&#x6D41;&#xFF0C;&#x6587;&#x4EF6;&#x6D41;&#x7B49;</li>
<li>&#x53D1;&#x8D77;&#x8BF7;&#x6C42;&#xFF1A;HttpWorker&#x662F;&#x8BF7;&#x6C42;&#x7684;&#x53D1;&#x8D77;&#x8005;&#xFF0C;&#x7531;&#x5404;&#x79CD;&#x7B2C;&#x4E09;&#x65B9;http&#x5E93;&#x5B9E;&#x73B0;&#xFF0C;&#x73B0;&#x5728;&#x652F;&#x6301;OkHttpWorker</li>
<li>&#x54CD;&#x5E94;&#xFF1A;&#x62FF;&#x5230;header&#xFF0C;&#x89E3;&#x6790;InputStream&#xFF0C;&#x4F7F;&#x7528;StreamConverter,&#x652F;&#x6301;byte[]&#xFF0C;File&#xFF0C;String&#x4E09;&#x79CD;&#x89E3;&#x6790;<ul>
<li>&#x8D85;&#x65F6;&#xFF0C;&#x6620;&#x5C04;&#x5230;BaseHttpCallback</li>
<li>404&#xFF0C; 500&#x7B49;&#xFF0C;&#x6620;&#x5C04;&#x5230;BaseHttpCallback</li>
<li>byte[]&#x548C;File&#x76F4;&#x63A5;&#x6620;&#x5C04;&#x5230;BaseHttpCallback</li>
</ul>
</li>
<li>&#x5BF9;&#x4E8E;String&#xFF0C;&#x53EF;&#x80FD;&#x662F;xml&#xFF0C;json&#xFF0C;protobuf&#x7B49;&#x683C;&#x5F0F;&#xFF0C;&#x5E76;&#x4E14;&#x91CC;&#x9762;&#x5206;&#x4E3A;&#x72B6;&#x6001;&#x5B57;&#x6BB5;&#x548C;&#x4E1A;&#x52A1;&#x5B57;&#x6BB5;<ul>
<li>TopLevelConverter&#x89E3;&#x6790;&#x72B6;&#x6001;&#x5B57;&#x6BB5;&#xFF0C;&#x5E76;&#x6620;&#x5C04;&#x5230;BaseHttpCallback&#xFF08;&#x8FD9;&#x4E2A;&#x5C31;&#x662F;&#x7528;&#x6237;&#x4F7F;&#x7528;&#x7684;callback&#xFF09;</li>
<li>ResposneConverter&#x89E3;&#x6790;&#x4E1A;&#x52A1;&#x5B57;&#x6BB5;&#xFF0C;&#x5E76;&#x6620;&#x5C04;&#x5230;BaseHttpCallback</li>
</ul>
</li>
<li>&#x5176;&#x4E2D;&#xFF0C;ResponseConverter&#x5BF9;&#x5E94;&#x4E0D;&#x540C;&#x7684;&#x89E3;&#x6790;&#x5668;&#xFF0C;&#x5982;FastJson&#xFF0C;Gson&#xFF0C;Xml&#x89E3;&#x6790;&#x5668;&#x7B49;</li>
<li>&#x7528;&#x6237;&#x5728;BaseHttpCallback&#x4E2D;&#x5B9E;&#x73B0;&#x81EA;&#x5DF1;&#x7684;&#x4E1A;&#x52A1;&#x903B;&#x8F91;</li>
</ul>
</li>
</ul>
<ul>
<li><p>&#x58F0;&#x660E;&#xFF1A;</p>
<ul>
<li>OkHttpWorker&#x4E0D;&#x662F;&#x76F4;&#x63A5;&#x57FA;&#x4E8E;OkHttp&#xFF0C;&#x800C;&#x662F;&#x57FA;&#x4E8E;&#x5F00;&#x6E90;&#x9879;&#x76EE;OkHttpUtils<ul>
<li>&#x5730;&#x5740;&#xFF1A;<a href="https://github.com/hongyangAndroid/okhttputils" target="_blank">https://github.com/hongyangAndroid/okhttputils</a></li>
</ul>
</li>
<li>StreamConverter&#x5982;&#x679C;&#x4F7F;&#x7528;FileConverter&#xFF0C;&#x5C31;&#x662F;&#x6587;&#x4EF6;&#x4E0B;&#x8F7D;&#xFF0C;&#x4F46;&#x6587;&#x4EF6;&#x4E0B;&#x8F7D;&#x8FD8;&#x662F;&#x6709;&#x5F88;&#x591A;&#x7EC6;&#x8282;&#x7684;&#xFF0C;&#x4E0D;&#x5EFA;&#x8BAE;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x6846;&#x67B6;<ul>
<li>&#x53C2;&#x8003;&#xFF1A;<a href="https://github.com/Aspsine/MultiThreadDownload&#xFF0C;&#x5DF2;&#x7528;&#x5728;&#x4E86;&#x6B63;&#x5F0F;&#x9879;&#x76EE;&#x91CC;&#xFF0C;&#x7701;&#x4E0D;&#x5C11;&#x52B2;" target="_blank">https://github.com/Aspsine/MultiThreadDownload&#xFF0C;&#x5DF2;&#x7528;&#x5728;&#x4E86;&#x6B63;&#x5F0F;&#x9879;&#x76EE;&#x91CC;&#xFF0C;&#x7701;&#x4E0D;&#x5C11;&#x52B2;</a></li>
</ul>
</li>
<li>StreamConverter&#x5982;&#x679C;&#x4F7F;&#x7528;ByteArrayConverter&#xFF0C;&#x5C31;&#x662F;byte[]&#xFF0C;&#x4F46;&#x4E00;&#x822C;&#x7528;&#x4E0D;&#x5230;&#xFF0C;&#x6240;&#x4EE5;&#x5E76;&#x672A;&#x771F;&#x6B63;&#x652F;&#x6301;</li>
<li>&#x6574;&#x4E2A;&#x6846;&#x67B6;&#x4EFF;&#x7167;&#x7684;&#x662F;retrofit&#xFF0C;&#x4E3B;&#x6846;&#x67B6;&#x7B80;&#x5355;&#x81F3;&#x6781;&#xFF0C;worker&#x548C;converter&#x4F5C;&#x4E3A;&#x63D2;&#x4EF6;&#x5316;&#x5B50;&#x6A21;&#x5757;&#xFF0C;&#x60F3;&#x7528;&#x54EA;&#x4E2A;&#xFF0C;&#x5C31;&#x5F15;&#x7528;&#x54EA;&#x4E2A;</li>
<li>&#x5728;&#x6B64;&#x611F;&#x8C22;&#x4E0A;&#x9762;&#x6D89;&#x53CA;&#x5230;&#x7684;&#x4E09;&#x4F4D;&#x4F5C;&#x8005;</li>
<li>http&#x539F;&#x7406;blog&#xFF1A;<a href="http://blog.csdn.net/lmj623565791/article/details/47911083" target="_blank">http://blog.csdn.net/lmj623565791/article/details/47911083</a></li>
<li>&#x4EFF;&#x7167;Retrofit&#x548C;OkHttpUtils&#xFF0C;&#x8D85;&#x65F6;&#x8BBE;&#x7F6E;&#xFF0C;cookie&#xFF0C;https&#x7B49;&#x7684;&#x914D;&#x7F6E;&#x9879;&#xFF0C;&#x90FD;&#x4F7F;&#x7528;okhttp&#x548C;volly&#x7684;&#x539F;&#x751F;&#x8BBE;&#x7F6E;&#xFF0C;&#x800C;&#x4E0D;&#x7EB3;&#x5165;&#x6846;&#x67B6;&#x5185;&#x7BA1;&#x7406;</li>
</ul>
</li>
<li><p>&#x58F0;&#x660E;2&#xFF1A;</p>
<ul>
<li>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#x652F;&#x6301;&#xFF1A;<ul>
<li>get</li>
<li>post<ul>
<li>post from</li>
<li>post string</li>
<li>post file</li>
</ul>
</li>
<li>put</li>
<li>delete</li>
<li>head</li>
<li>patch<ul>
<li>Json&#x89E3;&#x6790;&#x4E2D;&#x7684;TypeToken&#x5904;&#x7406;&#x7684;&#x8FD8;&#x4E0D;&#x5B8C;&#x5584;&#xFF0C;&#x9700;&#x8981;&#x81EA;&#x5DF1;&#x624B;&#x52A8;&#x4F20;&#x5165;&#xFF08;&#x5728;BaseHttpCallback&#x4F20;&#x5165;&#xFF09;</li>
<li>&#x4E0A;&#x4F20;&#x6587;&#x4EF6;&#x65F6;&#xFF0C;&#x4E0A;&#x4F20;&#x8FDB;&#x5EA6;&#x63D0;&#x793A;&#x6CA1;&#x6709;&#x5B9E;&#x73B0;</li>
<li>&#x91CD;&#x53D1;&#x7B56;&#x7565;&#xFF0C;&#x672C;&#x4EBA;&#x5C1A;&#x672A;&#x6DF1;&#x5165;&#x7814;&#x7A76;&#xFF0C;&#x8FD8;&#x4E0D;&#x77E5;&#x9053;&#x662F;&#x600E;&#x4E48;&#x56DE;&#x4E8B;</li>
<li>&#x7F13;&#x5B58;&#xFF0C;&#x4E5F;&#x672A;&#x6DF1;&#x5165;&#x7814;&#x7A76;</li>
<li>&#x54CD;&#x5E94;code&#x662F;300&#x5230;400&#x65F6;&#xFF0C;&#x662F;&#x91CD;&#x5B9A;&#x5411;&#xFF0C;&#x600E;&#x4E48;&#x5904;&#x7406;&#x7684;&#xFF0C;&#x4E5F;&#x4E0D;&#x77E5;&#x9053;</li>
<li>403&#x7684;&#x6388;&#x6743;&#x95EE;&#x9898;&#xFF0C;okhttp&#x53EF;&#x4EE5;&#x652F;&#x6301;</li>
<li>https&#x7684;&#x95EE;&#x9898;&#xFF0C;okhttp&#x4E5F;&#x652F;&#x6301;</li>
<li>&#x6240;&#x6709;&#x6388;&#x6743;&#x548C;https&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x672C;&#x6846;&#x67B6;&#x4E0D;&#x505A;&#x8FC7;&#x591A;&#x5C01;&#x88C5;&#xFF0C;&#x4F46;&#x5404;&#x4E2A;worker&#x4F1A;&#x66B4;&#x9732;&#x51FA;&#x5404;&#x4E2A;&#x5E93;&#x7684;&#x914D;&#x7F6E;&#x9879;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x914D;&#x7F6E;&#xFF0C;demo&#x4F1A;&#x7ED9;&#x51FA;</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>OKHttp&#x652F;&#x6301;&#x7684;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#xFF1A;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#x662F;&#x7EAF;okhttp&#x4EE3;&#x7801;</p>
<pre><code class="lang-java">Request request = <span class="hljs-keyword">new</span> Request.Builder()
        .url(<span class="hljs-string">&quot;https://api.github.com/markdown/raw&quot;</span>)

        <span class="hljs-comment">//all request methods</span>
        .get()
        .post(RequestBody.create(MEDIA_TYPE_MARKDOWN, file))
        .post(RequestBody)
        .put(RequestBody)
        .delete()
        .delete(RequestBody)
        .head()
        .patch(RequestBody)
        .method(method, RequestBody)
        <span class="hljs-comment">///</span>

        .addHeader(name, value)
        .cacheControl(CacheControl)
        .build();
</code></pre>
<p>RequestBody&#x5305;&#x62EC;&#xFF1A;</p>
<pre><code>//post file&#xFF1A;&#x5355;&#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#xFF0C;&#x4E0D;&#x4EE5;&#x952E;&#x503C;&#x5BF9;&#x7684;&#x5F62;&#x5F0F;&#xFF0C;&#x5E94;&#x8BE5;&#x4E5F;&#x6CA1;&#x6CD5;&#x5E26;&#x5176;&#x4ED6;post&#x53C2;&#x6570;
public static final MediaType MEDIA_TYPE_MARKDOWN = MediaType.parse(&quot;text/x-markdown; charset=utf-8&quot;);
RequestBody.create(MEDIA_TYPE_MARKDOWN, file)

//post multipart&#xFF1A;&#x8868;&#x5355;&#x4E0A;&#x4F20;&#x6587;&#x4EF6;&#xFF0C;&#x53EF;&#x591A;&#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#xFF0C;&#x53EF;&#x9644;&#x5E26;post&#x53C2;&#x6570;
RequestBody requestBody = new MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart(&quot;title&quot;, &quot;Square Logo&quot;)
        .addFormDataPart(&quot;image&quot;, &quot;logo-square.png&quot;, RequestBody.create(MEDIA_TYPE_PNG, new File(&quot;website/static/logo-square.png&quot;)))
        .build();

//form&#x8868;&#x5355;&#xFF1A;&#x666E;&#x901A;post
RequestBody formBody = new FormBody.Builder()
        .add(&quot;search&quot;, &quot;Jurassic Park&quot;)
        .build();

//post string
String postBody = &quot;&quot;
        + &quot;Releases\n&quot;
        + &quot;--------\n&quot;
        + &quot;\n&quot;
        + &quot; * _1.0_ May 6, 2013\n&quot;
        + &quot; * _1.1_ June 15, 2013\n&quot;
        + &quot; * _1.2_ August 11, 2013\n&quot;;
RequestBody.create(MEDIA_TYPE_MARKDOWN, postBody)

RequestBody.create&#x652F;&#x6301;&#xFF1A;byte[], ByteString&#xFF0C;File&#xFF0C;String


//post streaming&#xFF1A;&#x81EA;&#x5DF1;&#x6784;&#x5EFA;RequestBody
RequestBody requestBody = new RequestBody() {
      @Override public MediaType contentType() {
        return MEDIA_TYPE_MARKDOWN;
      }

      @Override public void writeTo(BufferedSink sink) throws IOException {
        sink.writeUtf8(&quot;Numbers\n&quot;);
        sink.writeUtf8(&quot;-------\n&quot;);
        for (int i = 2; i &lt;= 997; i++) {
          sink.writeUtf8(String.format(&quot; * %s = %s\n&quot;, i, factor(i)));
        }
      }

      private String factor(int n) {
        for (int i = 2; i &lt; n; i++) {
          int x = n / i;
          if (x * i == n) return factor(x) + &quot; &#xD7; &quot; + i;
        }
        return Integer.toString(n);
      }
    };

    Request request = new Request.Builder()
        .url(&quot;https://api.github.com/markdown/raw&quot;)
        .post(requestBody)
        .build();

//&#x5E26;&#x4E0A;&#x4F20;&#x8FDB;&#x5EA6;&#xFF1A;&#x9700;&#x8981;&#x62E6;&#x622A;&#x5668;&#xFF0C;&#x62E6;&#x622A;&#x4E0A;&#x9762;&#x6784;&#x5EFA;&#x7684;RequestBody
Request request = new Request.Builder()
    .url(&quot;https://publicobject.com/helloworld.txt&quot;)
    .build();

final ProgressListener progressListener = new ProgressListener() {
  @Override public void update(long bytesRead, long contentLength, boolean done) {
    System.out.println(bytesRead);
    System.out.println(contentLength);
    System.out.println(done);
    System.out.format(&quot;%d%% done\n&quot;, (100 * bytesRead) / contentLength);
  }
};

OkHttpClient client = new OkHttpClient.Builder()
    .addNetworkInterceptor(new Interceptor() {
      @Override public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());
        return originalResponse.newBuilder()
            .body(new ProgressResponseBody(originalResponse.body(), progressListener))
            .build();
      }
    })
    .build();

Response response = client.newCall(request).execute();
</code></pre><p>Okhttp&#x89E3;&#x6790;&#x53D1;&#x8D77;&#x8BF7;&#x6C42;&#xFF1A;</p>
<pre><code>private final OkHttpClient client = new OkHttpClient();
&#x540C;&#x6B65;&#xFF1A;Response response = client.newCall(request).execute();
&#x5F02;&#x6B65;&#xFF1A;enqueue&#x548C;callback&#xFF0C;&#x6CE8;&#x610F;&#x8FDB;&#x5EA6;&#x7684;callback&#x9700;&#x8981;&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#xFF08;&#x4E0A;&#x4F20;&#x8FDB;&#x5EA6;&#x548C;&#x4E0B;&#x8F7D;&#x8FDB;&#x5EA6;&#xFF09;
</code></pre><p>OKHttp&#x89E3;&#x6790;Response&#xFF1A;</p>
<pre><code>&#x89E3;&#x6790;code&#xFF0C;&#x5224;&#x65AD;&#x662F;&#x5426;&#x6210;&#x529F;&#xFF1A;
response.code()
response.isSuccessful()---code&#x662F;200&#x5C31;&#x662F;true

&#x89E3;&#x6790;Header
response.header(&quot;Server&quot;)
&#x6216;&#x8005;
Headers responseHeaders = response.headers();
for (int i = 0, size = responseHeaders.size(); i &lt; size; i++) {
  System.out.println(responseHeaders.name(i) + &quot;: &quot; + responseHeaders.value(i));
}

&#x89E3;&#x6790;Body&#xFF1A;ReponseBody
long contentLength = response.body().contentLenght()
MediaType mime = response.body().contentType()

String json = response.body().string()
byte[] bytes = response.body().bytes()
InputStream inputStream = response.body().byteStream()
Reader reader = response.body().charStream()
BufferedSource buffer = response.body().source();
</code></pre><ul>
<li>&#x5176;&#x4ED6;&#x95EE;&#x9898;&#xFF1A;<ul>
<li>okhttp&#x7684;CacheController</li>
<li>okhttp&#x7684;&#x5B89;&#x5168;&#x76F8;&#x5173;&#xFF0C;Authenticate&#xFF0C;Certificate&#xFF0C;handshake&#xFF0C;authenticator&#xFF0C;CertificatePinner&#xFF0C;trustManagerForCertificates</li>
<li>okhttp&#x7684;&#x62E6;&#x622A;&#x5668;&#x600E;&#x4E48;&#x7528;</li>
<li>okhttp&#x7684;cancel&#x8BF7;&#x6C42;</li>
<li>okhttp&#x7684;Callback</li>
<li>okhttp&#x7684;execute&#x548C;enqueue</li>
</ul>
</li>
</ul>
<h2 id="2-&#x4F7F;&#x7528;">2 &#x4F7F;&#x7528;</h2>
<ul>
<li><p>&#x5F15;&#x5E93;&#xFF0C;&#x9700;&#x8981;3&#x4E2A;&#x5E93;&#xFF0C;&#x6838;&#x5FC3;&#x5E93;&#xFF0C;converter&#x5E93;&#xFF0C;worker&#x5E93;</p>
<ul>
<li>&#x6838;&#x5FC3;&#x5E93;&#x63D0;&#x4F9B;&#x4E86;&#x57FA;&#x672C;&#x6846;&#x67B6;&#xFF0C;&#x4F46;&#x4E0D;&#x5177;&#x5907;&#x5B9E;&#x9645;&#x529F;&#x80FD;<ul>
<li>compile &apos;org.ayo:ayo-http:v1.0.0&apos;</li>
</ul>
</li>
<li>converter&#x5E93;&#x63D0;&#x4F9B;&#x4E86;&#x5BF9;&#x4E1A;&#x52A1;&#x5B57;&#x6BB5;&#x7684;&#x89E3;&#x6790;&#xFF0C;&#x73B0;&#x5728;&#x53EA;&#x652F;&#x6301;fastjson<ul>
<li>compile &apos;org.ayo.http:converter-fastjson:v1.0.0&apos;</li>
</ul>
</li>
<li>worker&#x5E93;&#x652F;&#x6301;&#x5B9A;&#x5236;&#x5E95;&#x5C42;http&#x5B9E;&#x73B0;&#xFF0C;&#x73B0;&#x5728;&#x53EA;&#x652F;&#x6301;okhttp3<ul>
<li>compile &apos;org.ayo.http:worker-okhttp:v1.0.0&apos;</li>
</ul>
</li>
</ul>
</li>
<li><p>&#x9879;&#x76EE;&#x4EE3;&#x7801;</p>
<ul>
<li>&#x4F60;&#x9700;&#x8981;&#x81EA;&#x5DF1;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x72B6;&#x6001;&#x5B57;&#x6BB5;&#x89E3;&#x6790;&#x5668;&#xFF0C;&#x56E0;&#x4E3A;&#x5404;&#x4E2A;&#x9879;&#x76EE;&#x90FD;&#x4E0D;&#x4E00;&#x6837;&#xFF0C;&#x4E00;&#x822C;&#x5F62;&#x5F0F;&#x662F;&#xFF1A;{ code: 0, msg: &quot;&#x9519;&#x8BEF;&#x539F;&#x56E0;&quot;, result:[]&#x6216;{} }</li>
<li>&#x65E5;&#x5FD7;&#x76F8;&#x5173;&#xFF0C;&#x53C2;&#x8003;demo</li>
</ul>
</li>
</ul>
<pre><code class="lang-java">
<span class="hljs-meta">@Override</span>
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onCreate</span><span class="hljs-params">(Bundle savedInstanceState)</span> </span>{
    <span class="hljs-keyword">super</span>.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    <span class="hljs-comment">///&#x4E0B;&#x9762;&#x8FD9;&#x90E8;&#x5206;&#x4EE3;&#x7801;&#xFF0C;&#x5C31;&#x662F;&#x56FA;&#x5B9A;&#x6A21;&#x5F0F;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6CE8;&#x89E3;&#x751F;&#x6210;&#xFF0C;&#x5F53;&#x7136;retrofit&#x652F;&#x6301;&#xFF0C;&#x8FD9;&#x91CC;&#x4E0D;&#x652F;&#x6301;</span>
    getRequest().flag(<span class="hljs-string">&quot;&#x6D4B;&#x8BD5;&#x63A5;&#x53E3;&quot;</span>)
            .actionGet()
            .url(<span class="hljs-string">&quot;http://chuanyue.iwomedia.cn/daogou/app/app?jid={jid}&quot;</span>)
            .header(<span class="hljs-string">&quot;deviceId&quot;</span>, <span class="hljs-string">&quot;11122334&quot;</span>)               <span class="hljs-comment">//----&#x8BF7;&#x6C42;&#x5934;</span>
            .path(<span class="hljs-string">&quot;jid&quot;</span>, <span class="hljs-string">&quot;234&quot;</span>)                           <span class="hljs-comment">//----path&#x53C2;&#x6570;&#xFF0C;&#x4F1A;&#x66FF;&#x6362;&#x6389;url&#x4E2D;&#x7684;{key}</span>
            .queryString(<span class="hljs-string">&quot;nickname&quot;</span>, <span class="hljs-string">&quot;&#x54C8;&#x54C8;&quot;</span>)              <span class="hljs-comment">//----get&#x53C2;&#x6570;&#xFF0C;&#x4F1A;&#x62FC;&#x5230;url&#x4E2D;</span>
            .queryString(<span class="hljs-string">&quot;os&quot;</span>, <span class="hljs-string">&quot;android&quot;</span>)
<span class="hljs-comment">//                .path(&quot;id&quot;, &quot;1&quot;)</span>
<span class="hljs-comment">//                .param(&quot;pwd&quot;, &quot;dddddfffggghhh&quot;)         //----post&#x53C2;&#x6570;&#xFF0C;form&#x63D0;&#x4EA4;</span>
<span class="hljs-comment">//                .param(&quot;file-1&quot;, new File(&quot;&quot;))          //----post&#x53C2;&#x6570;&#xFF0C;&#x4E0A;&#x4F20;&#x6587;&#x4EF6;&#xFF0C;&#x53EF;&#x591A;&#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#xFF0C;multipart&#x7684;form&#x63D0;&#x4EA4;</span>
<span class="hljs-comment">//                .file(new File(&quot;&quot;))                     //----post&#x63D0;&#x4EA4;&#x6587;&#x4EF6;&#xFF0C;&#x53EA;&#x652F;&#x6301;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;post stream&#x65B9;&#x5F0F;</span>
<span class="hljs-comment">//                .stringEntity(&quot;hahahahahahahah&#x54C8;&#x54C8;&#x54C8;&#x54C8;&#x54C8;&#x54C8;&#x54C8;&#x54C8;lddddddddd2222222222&quot;) //----post&#x63D0;&#x4EA4;&#x6587;&#x672C;&#xFF0C;post stream&#x65B9;&#x5F0F;</span>
            .callback(<span class="hljs-keyword">new</span> BaseHttpCallback&lt;List&lt;RespRegist&gt;&gt;() {
                <span class="hljs-meta">@Override</span>
                <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onFinish</span><span class="hljs-params">(<span class="hljs-keyword">boolean</span> isSuccess, HttpProblem problem, FailInfo resp, List&lt;RespRegist&gt; respRegist)</span> </span>{
                    <span class="hljs-keyword">if</span>(isSuccess){
                        Toast.makeText(getApplicationContext(), <span class="hljs-string">&quot;&#x8BF7;&#x6C42;&#x6210;&#x529F;--&quot;</span> + respRegist.size(), Toast.LENGTH_SHORT).show();
                    }<span class="hljs-keyword">else</span>{
                        Toast.makeText(getApplicationContext(), <span class="hljs-string">&quot;&#x8BF7;&#x6C42;&#x5931;&#x8D25;&#xFF1A;&quot;</span> + resp.dataErrorReason, Toast.LENGTH_SHORT).show();
                    }
                }

                <span class="hljs-meta">@Override</span>
                <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onLoading</span><span class="hljs-params">(<span class="hljs-keyword">long</span> current, <span class="hljs-keyword">long</span> total)</span> </span>{
                    <span class="hljs-keyword">super</span>.onLoading(current, total);
                }
            }, <span class="hljs-keyword">new</span> TypeToken&lt;List&lt;RespRegist&gt;&gt;(){})
            .fire();


}

<span class="hljs-function"><span class="hljs-keyword">public</span> AyoHttp <span class="hljs-title">getRequest</span><span class="hljs-params">()</span></span>{
    <span class="hljs-keyword">return</span> AyoHttp.request()
                .connectionTimeout(<span class="hljs-number">10000</span>)
                .writeTimeout(<span class="hljs-number">10000</span>)
                .readTimeout(<span class="hljs-number">10000</span>)
                .worker(<span class="hljs-keyword">new</span> OkhttpWorker())
                .streamConverter(<span class="hljs-keyword">new</span> StreamConverter.StringConverter())   <span class="hljs-comment">//ByteArrayConverter   FileConverter</span>
                .topLevelConverter(<span class="hljs-keyword">new</span> SampleTopLevelConverter())
                .resonseConverter(<span class="hljs-keyword">new</span> FastJsonConverter())
                .intercept(<span class="hljs-keyword">new</span> LogIntercepter());
}
</code></pre>
<h1 id="volly&#x6E90;&#x7801;&#x89E3;&#x6790;">Volly&#x6E90;&#x7801;&#x89E3;&#x6790;</h1>
<ul>
<li>HTTP&#x8BF7;&#x6C42;<ul>
<li>&#x5982;&#x4F55;&#x6784;&#x9020;&#x4E00;&#x4E2A;&#x8BF7;&#x6C42;</li>
<li>&#x53D1;&#x8D77;&#x8BF7;&#x6C42;&#xFF0C;&#x7BA1;&#x7406;&#x8BF7;&#x6C42;&#xFF1A;RequestQueue</li>
<li>&#x54CD;&#x5E94;</li>
<li>&#x4F7F;&#x7528;&#x8BE6;&#x89E3;</li>
</ul>
</li>
</ul>
<h3 id="">#</h3>
<h2 id="1-&#x6784;&#x9020;&#x4E00;&#x4E2A;&#x8BF7;&#x6C42;&#xFF1A;request">1 &#x6784;&#x9020;&#x4E00;&#x4E2A;&#x8BF7;&#x6C42;&#xFF1A;Request</h2>
<ul>
<li><p>http&#x8BF7;&#x6C42;&#xFF1A;</p>
<ul>
<li>Request.Method&#x679A;&#x4E3E;&#x4E86;&#x6240;&#x6709;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;</li>
<li>get&#x8BF7;&#x6C42;&#xFF1A;&#x9700;&#x8981;&#x4F20;&#x5165;url&#xFF0C;&#x62FC;&#x63A5;query parameters<ul>
<li>StringRequest</li>
<li>RequestManager.get()</li>
</ul>
</li>
<li>post&#x8BF7;&#x6C42;1&#xFF1A;&#x666E;&#x901A;post&#xFF0C;&#x5E26;request parameters<ul>
<li>StringRequest</li>
<li>RequestManager.post()</li>
</ul>
</li>
<li>post&#x8BF7;&#x6C42;2&#xFF1A;&#x4F20;&#x5165;StringEntity<ul>
<li>ByteArrayRequest&#xFF0C;&#x4F46;&#x662F;&#x8FD9;&#x4E2A;&#x7C7B;&#x53EA;&#x6709;package&#x6743;&#x9650;</li>
<li>&#x53EA;&#x80FD;&#x7528;RequestManager.sendRequest&#x6216;&#x8005;post</li>
</ul>
</li>
<li>post&#x8BF7;&#x6C42;3&#xFF1A;&#x4E0A;&#x4F20;&#x6587;&#x4EF6;<ul>
<li>&#x7528;&#x5230;RequestMap&#xFF0C;&#x8FD9;&#x4E2A;&#x7C7B;&#x53EF;&#x4EE5;&#x5F80;&#x91CC;&#x4F20;file&#xFF0C;inputstream&#x7B49;</li>
<li>RequestManager.sendRequest&#x6216;&#x8005;post&#x65B9;&#x6CD5;&#x4E2D;&#x53C2;&#x6570;data&#x7684;&#x5C31;&#x662F;RequestMap</li>
</ul>
</li>
<li>PUT</li>
<li>DELETE</li>
<li>HEAD</li>
<li>OPTIONS</li>
<li>TRACE</li>
<li>PATCH</li>
</ul>
</li>
<li><p>&#x6D4B;&#x8BD5;&#x63A5;&#x53E3;</p>
<ul>
<li>get :</li>
<li>post 1: StringRequest</li>
<li>post 2: &#x5F97;&#x7528;&#x5230;</li>
<li>&#x4E0A;&#x4F20;&#x6587;&#x4EF6;</li>
<li>&#x4E0B;&#x8F7D;&#x6587;&#x4EF6;</li>
<li>PUT</li>
<li>DELETE</li>
<li>HEAD</li>
<li>OPTIONS</li>
<li>TRACE</li>
<li>PATCH</li>
<li>&#x4EFF;&#x9A8C;&#x8BC1;&#x7801;&#x8BF7;&#x6C42;</li>
</ul>
</li>
</ul>
<h3 id="hurlstack">HurlStack</h3>
<p>1 &#x5904;&#x7406;&#x5E95;&#x5C42;http&#x8BF7;&#x6C42;&#xFF0C;&#x4F7F;&#x7528;&#x4E86;URLConnection&#xFF0C;&#x5927;&#x4F53;&#x4E0A;&#x5C31;&#x662F;&#x6839;&#x636E;Request&#xFF0C;&#x8FD4;&#x56DE;Response</p>
<p>2 POST&#xFF0C;PUT&#xFF0C;PATCH&#x8FD9;&#x4E09;&#x79CD;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#x4F1A;&#x6DFB;&#x52A0;body&#xFF0C;&#x6240;&#x6709;&#x4F1A;&#x8C03;&#x7528;&#xFF1A;addBodyIfExists</p>
<pre><code class="lang-java"><span class="hljs-keyword">byte</span>[] body = request.getBody();
<span class="hljs-keyword">if</span> (body != <span class="hljs-keyword">null</span>) {
    connection.setDoOutput(<span class="hljs-keyword">true</span>);
    connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType());
    DataOutputStream out = <span class="hljs-keyword">new</span> DataOutputStream(connection.getOutputStream());
    out.write(body);
    out.close();
}

<span class="hljs-comment">///&#x6CE8;&#x610F;&#xFF0C;body&#x5206;&#x591A;&#x79CD;&#xFF0C;post&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF0C;post entity&#xFF0C;&#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#x7B49;</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;request.getBody()&#xFF0C;&#x6BCF;&#x4E00;&#x79CD;Request&#x90FD;&#x4F1A;&#x628A;&#x81EA;&#x5DF1;&#x7684;&#x6240;&#x6709;&#x53C2;&#x6570;&#x8F6C;&#x5316;&#x4E3A;&#x4E00;&#x4E2A;body&#xFF0C;&#x6D89;&#x53CA;&#x5230;&#x952E;&#x503C;&#x5BF9;&#xFF0C;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x6587;&#x4EF6;&#xFF0C;&#x8F93;&#x5165;&#x6D41;&#x7B49;</p>
<p>3 &#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x7B49;&#x5728;&#x8FD9;&#x91CC;&#x8BBE;&#x7F6E;</p>
<p>4 &#x8FD4;&#x56DE;HttpResponse&#xFF1A;</p>
<ul>
<li>HttpResponse&#x91CC;&#x5C01;&#x88C5;&#x4E86;&#xFF1A;<ul>
<li>connection.getInputStream()&#xFF0C;&#x8FD8;&#x6CA1;&#x8BFB;&#x5462;</li>
<li>content length&#x7B49;&#x53C2;&#x6570;</li>
<li>&#x54CD;&#x5E94;&#x7684;header</li>
</ul>
</li>
</ul>
<h3 id="network&#xFF0C;&#x53CA;&#x5176;&#x5B50;&#x7C7B;basicnetwork">Network&#xFF0C;&#x53CA;&#x5176;&#x5B50;&#x7C7B;BasicNetwork</h3>
<ul>
<li>&#x6709;&#x4F55;&#x7528;<ul>
<li>&#x9A71;&#x52A8;&#x4E86;HurlStack</li>
<li>&#x5904;&#x7406;&#x7F13;&#x5B58;&#xFF1A;&#x5E95;&#x5C42;&#x7684;&#x7F13;&#x5B58;</li>
<li>&#x91CD;&#x5B9A;&#x5411;</li>
<li>&#x628A;IO&#x5F02;&#x5E38;&#x5C01;&#x88C5;&#x6210;Volly&#x5F02;&#x5E38;</li>
<li>&#x5904;&#x7406;retry policy: attemptRetryOnException&#x65B9;&#x6CD5;</li>
</ul>
</li>
</ul>
<hr>
<p>&#x4E0D;&#x61C2;&#xFF1A;ByteArrayPool&#x8FD9;&#x4E2A;&#x662F;&#x5E72;&#x4EC0;&#x4E48;&#x7684;</p>
<pre><code class="lang-java"><span class="hljs-comment">//&#x8FD4;&#x56DE;&#xFF1A;</span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> NetworkResponse(statusCode, responseContents,
                            responseHeaders, <span class="hljs-keyword">false</span>,
                            SystemClock.elapsedRealtime() - requestStart);
&#x5176;&#x4E2D;responseContents&#xFF0C;&#x662F;&#x4E00;&#x4E2A;<span class="hljs-keyword">byte</span>[]&#xFF0C;&#x5C31;&#x662F;&#x628A;hurlStack&#x8FD4;&#x56DE;&#x7684;inputStream&#x8BFB;&#x51FA;&#x6765;&#x4E86;&#xFF0C;
&#x8FD9;&#x4E2A;&#x529F;&#x80FD;&#x7531;entityToBytes&#x65B9;&#x6CD5;&#x5B8C;&#x6210;&#xFF0C;&#x91CC;&#x9762;&#x7528;&#x5230;&#x4E86;ByteArrayPool
</code></pre>
<h3 id="requestqueue">RequestQueue</h3>
<ul>
<li><p>&#x5FC5;&#x987B;&#x8C03;&#x7528;start()&#x65B9;&#x6CD5;&#x6765;&#x542F;&#x52A8;volly&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x8BA4;&#x4E3A;volly&#x542F;&#x52A8;&#x53EA;&#x6709;&#x6709;&#x4E2A;&#x5927;&#x5FAA;&#x73AF;</p>
<ul>
<li>&#x7B49;&#x5F85;&#x961F;&#x5217;&#xFF1A;Map<string, queue<request<?="">&gt;&gt; mWaitingRequests</string,></li>
<li>&#x5E72;&#x6D3B;&#x961F;&#x5217;&#xFF1A; PriorityBlockingQueue<request<?>&gt; mNetworkQueue</request<?></li>
<li>&#x7F13;&#x5B58;&#x961F;&#x5217;&#xFF1A;PriorityBlockingQueue<request<?>&gt; mCacheQueue</request<?></li>
<li>&#x5F53;&#x524D;&#x96C6;&#x5408;&#xFF1A;Set<request<?>&gt; mCurrentRequests</request<?></li>
</ul>
</li>
<li><p>&#x9ED8;&#x8BA4;&#x7EBF;&#x7A0B;&#x6C60;&#xFF1A;</p>
<ul>
<li>DEFAULT_NETWORK_THREAD_POOL_SIZE = 4</li>
<li>&#x4E2A;&#x4EBA;&#x63A8;&#x8350;&#xFF1A;&#x6839;&#x636E;Rxjava&#x7684;&#x601D;&#x60F3;&#xFF1A;<ul>
<li>IO&#x7EBF;&#x7A0B;&#x5E94;&#x8BE5;&#x662F;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x6C60;&#xFF0C;&#x7EBF;&#x7A0B;&#x6570;&#x4E0D;&#x9650;&#xFF0C;&#x4F46;&#x91CD;&#x7528;&#x7A7A;&#x95F2;&#x7EBF;&#x7A0B;</li>
<li>CPU&#x5BC6;&#x96C6;&#x578B;&#x7EBF;&#x7A0B;&#xFF0C;&#x5373;&#x8BA1;&#x7B97;&#x5BC6;&#x96C6;&#x578B;&#xFF0C;&#x6709;&#x51E0;&#x4E2A;CPU&#xFF0C;&#x5C31;&#x6709;&#x51E0;&#x4E2A;&#x7EBF;&#x7A0B;</li>
</ul>
</li>
</ul>
</li>
<li><p>&#x5E72;&#x6D3B;&#x7684;&#x7C7B;&#xFF1A;</p>
<ul>
<li>Cache &#x548C; CacheDispatcher&#xFF1A;&#x9ED8;&#x8BA4;new DiskBasedCache(cacheDir)</li>
<li>Network &#x548C; NetworkDispatcher[]&#xFF1A; &#x6570;&#x7EC4;&#x5927;&#x5C0F;&#x5C31;&#x662F;&#x7EBF;&#x7A0B;&#x6C60;&#x5927;&#x5C0F;</li>
<li>ResponseDelivery&#xFF1A; &#x9ED8;&#x8BA4;new ExecutorDelivery(new Handler(Looper.getMainLooper()))</li>
<li>List<requestfinishedlistener> mFinishedListeners</requestfinishedlistener></li>
</ul>
</li>
</ul>
<h3 id="">#</h3>
<ul>
<li>&#x521D;&#x59CB;&#x5316;&#xFF1A;start() &#x5927;&#x5FAA;&#x73AF;&#x5F00;&#x59CB;<ul>
<li>CacheDispatcher&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;thread&#xFF0C;&#x542F;&#x52A8;&#x4E86;&#xFF0C;&#x5904;&#x7406;&#x7684;&#x662F;mCacheQueue</li>
<li>NetworkDispatcher&#x4F5C;&#x4E3A;n&#x4E2A;thread&#xFF0C;&#x542F;&#x52A8;&#x4E86;&#xFF0C;n&#x7EA7;&#x7EBF;&#x7A0B;&#x6C60;&#x7684;&#x7EBF;&#x7A0B;&#x6570;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;4&#xFF0C;&#x5904;&#x7406;&#x7684;&#x662F;mNetworkQueue</li>
</ul>
</li>
</ul>
<h3 id="">#</h3>
<ul>
<li>NetworkDispatcher&#x600E;&#x4E48;&#x5DE5;&#x4F5C;&#xFF1F;<ul>
<li>&#x7EBF;&#x7A0B;&#x4F18;&#x5148;&#x7EA7;&#xFF1A;Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND)</li>
<li>&#x5904;&#x7406;&#x7684;&#x662F;mNetworkQueue</li>
<li>&#x5BF9;&#x4E8E;&#x6BCF;&#x4E00;&#x4E2A;Request&#xFF1A;<ul>
<li>&#x8C03;&#x7528;NetWork.performRequest(request)&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;BasicNetwork</li>
<li>&#x54CD;&#x5E94;&#x7ED3;&#x679C;&#x9884;&#x5904;&#x7406;&#xFF1A;Response&lt;?&gt; response = request.parseNetworkResponse(networkResponse)&#xFF0C;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x662F;&#x628A;byte[]&#x8F6C;&#x6210;Request<t>&#x7684;&#x8FD9;&#x4E2A;T&#x7C7B;&#x578B;&#xFF0C;&#x5982;&#x53D8;&#x6210;String&#xFF0C;&#x6587;&#x4EF6;&#x7B49;</t></li>
<li>&#x5904;&#x7406;&#x7F13;&#x5B58;&#xFF1A;mCache.put(request.getCacheKey(), response.cacheEntry);  &#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;&#xFF1F;<ul>
<li>&#x6BCF;&#x4E00;&#x4E2A;&#x8BF7;&#x6C42;&#x6709;&#x4E2A;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#xFF0C;&#x9ED8;&#x8BA4;url</li>
</ul>
</li>
<li>&#x8F6C;&#x53D1;&#x54CD;&#x5E94;&#xFF1A;ResponseDelivery.postResponse(request, response)&#xFF0C;&#x9ED8;&#x8BA4;&#x5B9E;&#x73B0;&#x662F;ExecutorDelivery<ul>
<li>&#x6CE8;&#x610F;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x662F;&#x4E2A;&#x5E26;&#x4E3B;&#x5FAA;&#x73AF;&#x7684;handler&#xFF1A;new ExecutorDelivery(new Handler(Looper.getMainLooper()))</li>
<li>&#x6240;&#x6709;&#x4EE3;&#x7801;&#x90FD;&#x5728;&#x4E3B;&#x7EBF;&#x7A0B;&#x8FD0;&#x884C;</li>
<li>&#x8F6C;&#x53D1;&#x5230;RequestQueue&#x7684;RequestFinishedListener&#xFF1A;&#x8FD9;&#x4E2A;&#x662F;&#x5927;&#x56DE;&#x8C03;&#xFF0C;&#x76D1;&#x542C;&#x6240;&#x6709;&#x8BF7;&#x6C42;&#xFF0C;&#x53EF;&#x4EE5;&#x6839;&#x636E;id&#x7B5B;&#x9009;</li>
<li>&#x8F6C;&#x53D1;&#x5230;&#x6BCF;&#x4E2A;reqeust&#x7684;deliverResponse&#x65B9;&#x6CD5;&#xFF0C;&#x5982;StringReuqest&#xFF0C;&#x7528;&#x5230;&#x4E86;Response.Listener</li>
</ul>
</li>
<li>&#x57FA;&#x672C;&#x5B8C;&#x4E8B;</li>
</ul>
</li>
<li>&#x603B;&#x7ED3;&#xFF1A;<ul>
<li>&#x6BCF;&#x4E2A;NetworkDispatcher&#x90FD;&#x4ECE;&#x961F;&#x5217;&#x91CC;take&#xFF0C;&#x8C01;&#x5FEB;&#x8C01;&#x5C31;take&#x4E0B;&#x4E00;&#x4E2A;</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="">#</h3>
<ul>
<li>&#x7F13;&#x5B58;&#x76F8;&#x5173;&#xFF1A;<ul>
<li>&#x5B58;&#x7684;&#x503C;&#x7C7B;&#x578B;&#x662F;Cache.Entry&#xFF0C;&#x5B58;&#x7684;&#x662F;http&#x54CD;&#x5E94;&#x4E2D;&#x7684;byte[]&#xFF0C;header&#xFF0C;&#x72B6;&#x6001;&#x5B57;&#x6BB5;&#x7B49;</li>
<li>&#x53D6;&#x51FA;&#xFF1A;&#x5728;BasicNetwork&#x4E2D;&#xFF0C;<ul>
<li>&#x5982;&#x679C;http&#x54CD;&#x5E94;&#x662F;not modified&#x7684;&#xFF0C;&#x5C31;&#x4E0D;&#x505A;&#x8FDB;&#x4E00;&#x6B65;&#x89E3;&#x6790;&#x4E86;&#xFF0C;&#x800C;&#x662F;&#x4ECE;cache&#x53D6;&#x51FA;&#x5DF2;&#x7ECF;&#x89E3;&#x6790;&#x597D;&#x7684;&#x4E1C;&#x897F;<ul>
<li>Entry entry = request.getCacheEntry();</li>
</ul>
</li>
<li>&#x4F46;&#x8FD9;&#x4E2A;entry&#x662F;&#x8C01;&#x653E;&#x8FDB;request&#x91CC;&#x7684;&#x5462;, &#x5728;CacheDispatcher&#xFF0C;111&#x884C;</li>
</ul>
</li>
<li>&#x4FDD;&#x5B58;&#xFF1A;&#x5728;NetworkDispatcher&#x4E2D;&#xFF0C;&#x4FDD;&#x5B58;&#xFF0C;mCache.put(request.getCacheKey(), response.cacheEntry);<ul>
<li>request.getCacheKey()&#xFF0C;&#x9ED8;&#x8BA4;&#x5C31;&#x662F;url&#xFF0C;&#x53EA;&#x5BF9;get&#x8BF7;&#x6C42;&#x505A;&#x7F13;&#x5B58;&#xFF1F;</li>
<li>response.cacheEntry&#xFF0C;&#x5728;Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response))&#x65F6;&#x8D4B;&#x503C;&#xFF0C;&#x53C2;&#x8003;StringRequest.parseNetworkResponse</li>
</ul>
</li>
<li>ClearCacheRequest&#xFF1A;&#x4E00;&#x4E2A;&#x865A;&#x6784;&#x7684;&#x8BF7;&#x6C42;&#xFF08;&#x5E26;hack&#x6027;&#x8D28;&#x7684;&#x8BF7;&#x6C42;&#xFF09;&#xFF0C;&#x8C03;&#x7528;isCanceled&#xFF0C;&#x4F1A;&#x6E05;&#x7A7A;&#x7F13;&#x5B58;&#xFF0C; cache.clear()&#xFF0C;&#x5E76;&#x5728;handler&#x961F;&#x5217;&#x7684;&#x6700;&#x524D;&#x9762;&#x6267;&#x884C;&#x4E00;&#x4E2A;runnable&#x7684;callback</li>
<li>&#x63A5;&#x53E3;&#x662F;&#xFF1A;Cache</li>
<li>&#x770B;&#x9ED8;&#x8BA4;&#x5B9E;&#x73B0;&#x7C7B;&#xFF1A;DiskBasedCache<ul>
<li>&#x6587;&#x4EF6;&#x4FDD;&#x5B58;</li>
</ul>
</li>
<li>CacheDispatcher&#x5982;&#x4F55;&#x5DE5;&#x4F5C;&#xFF1F;<ul>
<li>&#x72EC;&#x81EA;&#x542F;&#x52A8;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#xFF0C;&#x5360;&#x4E00;&#x4E2A;&#x5927;&#x5FAA;&#x73AF;&#xFF0C;&#x5728;mCacheQueue&#x961F;&#x5217;&#x4E2D;&#x5DE5;&#x4F5C;</li>
<li>&#x6CA1;&#x6709;&#x7F13;&#x5B58;&#xFF0C;&#x5219;&#x653E;&#x56DE;mNetworkQueue&#xFF0C;&#x7B49;NetworkDispatcher&#x5904;&#x7406;</li>
<li>&#x6709;&#x7F13;&#x5B58;&#xFF0C;&#x4F46;&#x5DF2;&#x8FC7;&#x671F;<ul>
<li>&#x5219;&#x5148;&#x628A;&#x7F13;&#x5B58;&#x653E;&#x5230;request.cacheEntry&#x91CC;</li>
<li>&#x518D;&#x628A;request&#x653E;&#x5230;mNetworkQueue</li>
<li>&#x5982;&#x679C;&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE;&#x7684;&#x7ED3;&#x679C;&#x662F;not modified&#xFF0C;&#x5219;&#x4F7F;&#x7528;&#x7F13;&#x5B58;&#xFF0C;&#x5426;&#x5219;&#x5FFD;&#x7565;&#x7F13;&#x5B58;</li>
</ul>
</li>
<li>&#x6709;&#x7F13;&#x5B58;&#xFF0C;&#x4E14;&#x6709;&#x6548;&#xFF0C;&#x76F4;&#x63A5;deliver&#x51FA;&#x53BB;</li>
<li>&#x6709;&#x7F13;&#x5B58;&#xFF0C;&#x4E14;&#x6709;&#x6548;&#xFF0C;&#x4F46;&#x5DF2;&#x88AB;&#x8BBE;&#x7F6E;&#x4E3A;&#x9700;&#x8981;&#x5237;&#x65B0;&#xFF0C;&#x4E5F;&#x662F;&#x56DE;&#x5230;mNetworkQueue&#xFF0C;&#x548C;modified&#x72B6;&#x6001;&#x503C;&#x5BF9;&#x6BD4;</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="">#</h3>
<ul>
<li>RequestQueue.add(Request&lt;?&gt; request)<ul>
<li>&#x6D89;&#x53CA;&#x5230;mCurrentRequests&#xFF0C;mNetworkQueue&#xFF0C;mWaitingRequests&#xFF0C;mCacheQueue</li>
</ul>
</li>
</ul>
<h3 id="stringrequest">StringRequest</h3>
<p>&#x4F20;&#x5165;&#x952E;&#x503C;&#x5BF9;&#xFF0C;&#x4EE5;get&#xFF0C;post&#x7B49;&#x65B9;&#x5F0F;&#x53D1;&#x8D77;&#x8BF7;&#x6C42;</p>
<p>&#x54CD;&#x5E94;&#x662F;String</p>
<h3 id="bytearrayrequest&#xFF1A;&#x901A;&#x8FC7;requestmanager&#x4F7F;&#x7528;">ByteArrayRequest&#xFF1A;&#x901A;&#x8FC7;RequestManager&#x4F7F;&#x7528;</h3>
<h3 id="requestmap&#xFF1A;&#x4E0A;&#x4F20;&#x6587;&#x4EF6;&#xFF0C;&#x4F46;&#x662F;&#x56DE;&#x8C03;&#x4E2D;&#x6CA1;&#x6709;&#x8FDB;&#x5EA6;&#x63D0;&#x793A;">RequestMap&#xFF1A;&#x4E0A;&#x4F20;&#x6587;&#x4EF6;&#xFF0C;&#x4F46;&#x662F;&#x56DE;&#x8C03;&#x4E2D;&#x6CA1;&#x6709;&#x8FDB;&#x5EA6;&#x63D0;&#x793A;</h3>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="lang.html" class="navigation navigation-prev " aria-label="Previous page: 常用工具类">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="xml.html" class="navigation navigation-next " aria-label="Next page: xml解析">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"http","level":"2.4","depth":1,"next":{"title":"xml解析","level":"2.5","depth":1,"path":"xml.md","ref":"xml.md","articles":[]},"previous":{"title":"常用工具类","level":"2.3","depth":1,"path":"lang.md","ref":"lang.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"http.md","mtime":"2017-04-09T10:52:51.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-04-09T17:03:25.521Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

